<?php

namespace Common\Model;

/**
 * VipUserCardModel.class.php实例模型
 *
 * @modify wenhui 2017-12-06    创建
 * @date 2017-12-06
 */
class VipUserCardModel extends BaseModel {

    protected $trueTableName = 'tb_vip_user_card';

    /**
     * 返回数据
     * @modify wenhui 2017-12-06    创建
     * @param integer $vipUserId 客栈ID
     * @return array
     */
    public function getInfoByVipUserId($vipUserId) {
        $option = [
            'vipuser_id'=> $vipUserId,
            'isdelete'=> NOT_DELETE,
        ];
        $field = 'id,vipuser_id,price';
        $data = $this->field($field)->where($option)->find();

        return empty($data) ? array() : $data;
    }

    /**
     * 添加用户数据
     * @modify wenhui 2017-12-06    创建
     * @param int  $vipUserId           会员id
     * @param decimod  $cardPrice        金额
     * @return id
     */
    public function addVipUserCardInfo ($hotelId, $vipUserId, $price, $creator, $operator) {
        $data = [
            'hotelentity_id' => $hotelId,
            'vipuser_id' => $vipUserId,
            'price' => $price,
            'creator' => $creator,
            'operator' => $operator,
        ];

        return $this->add($data);
    }

    /**
     * 更新用户数据
     * @modify wenhui 2017-12-06    创建
     * @param int  $vipUserId           会员id
     * @param decimod  $cardPrice        金额
     * @return id
     */
    public function saveVipUserCardInfo($vipUserId, $price) {
        $option['vipuser_id'] = $vipUserId;
        $data['price'] = $price;

        $result = $this->where($option)->save($data);
        return $result === false ? false : true;
    }

}
